package GUI.test1;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import edu.sjsu.cs.phan.BankAccount;

public class MoneyTracker
{
   public static void main(String[] args)
   {
      JFrame frame = new JFrame();
      JPanel panel = new JPanel();
      
      JButton button = new JButton("Deposit");
      JButton button1 = new JButton("Balance");
      JButton button2 = new JButton("Withdraw");
      
      button.setSize(40, 20);
      frame.setSize(400, 100);
      
      panel.add(button);
      panel.add(button1);
      panel.add(button2);
      
      frame.add(panel);
      
      final BankAccount account = new BankAccount(100);
      
      class Deposit implements ActionListener
      {

         public void actionPerformed(ActionEvent e)
         {
            String NewBalance = JOptionPane.showInputDialog(null, "Input");
            double balance = Double.parseDouble(NewBalance);
            account.deposit(balance);
         }
         
      }
      class Balance implements ActionListener
      {

         public void actionPerformed(ActionEvent e)
         {
            JOptionPane.showMessageDialog(null, account.getBalance());
         }
         
      }
      class Withdraw implements ActionListener
      {

         public void actionPerformed(ActionEvent e)
         {
            String NewBalance = JOptionPane.showInputDialog(null, "Input");
            double balance = Double.parseDouble(NewBalance);
            account.withdraw(balance);
         }
         
      }
      
      ActionListener listener = new Deposit();
      ActionListener listener1 = new Balance();
      ActionListener listener2 = new Withdraw();
      
      button.addActionListener(listener);
      button1.addActionListener(listener1);
      button2.addActionListener(listener2);
      
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
      
   }
}
